#version 320 es
precision mediump float;
in vec3 Normal;
in vec3 FragPos;
in vec2 u_v;
struct Material{
    //sampler2D ambientColor;
    sampler2D diffuseColor;
    sampler2D specularColor;
    vec2 shine;            //高光发光强度
};
struct Light{
    vec3 ambientStrength;
    vec3 diffuseStrength;
    vec3 specularStrength;
};
uniform vec3 viewPos;
uniform vec3 lightPos;
uniform Material material;
uniform Light light;
vec3 lightColor = vec3(1.0f);
out vec4 color;
void main(void) {
    vec3 normal = normalize(Normal);
    vec3 tex1 = vec3(texture(material.diffuseColor, u_v));
    //ambient
    vec3 ambientLight = tex1 * light.ambientStrength;
    //diffuse
    vec3 lightDir = normalize(lightPos - FragPos);
    float diffuse = max(dot(lightDir, normal), 0.0f);
    vec3 diffuseLight = tex1 * light.diffuseStrength * diffuse;
    //specular
    vec3 viewDir = normalize(viewPos - FragPos);
    //phong
    //vec3 refDir = normalize(reflect(-lightDir, normal));
    //float specular = pow(max(dot(viewDir, refDir), 0.0f), material.shine.x);
    //blinn-phong
    vec3 halfwayDir = normalize(viewDir + lightDir);
    float specular = pow(max(dot(halfwayDir, normal), 0.0f), material.shine.x);
    vec3 specularLight = vec3(texture(material.specularColor, u_v)) * light.specularStrength * specular;
    color = vec4((ambientLight + diffuseLight + specularLight) * lightColor, 1.0f);
}
